var panel = document.querySelector("#video .playerWrapper .detailPostPanel");
var ads = document.querySelector("#video .izYtAds");
var ytapiplayer = document.querySelector("#ytapiplayer");
var videoID = ytapiplayer.dataset.id;
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF(
  "https://www.youtube.com/v/"+videoID+"?enablejsapi=1&playerapiid=ytplayer&version=3",
  "ytapiplayer", 
  "425", 
  "356", 
  "8", 
  null, 
  null, 
  params, 
  atts
);
  
  
function onYouTubePlayerReady(playerId) {
  var ytplayer = document.querySelector("#myytplayer");
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
  // console.log(ytplayer)
}
function onytplayerStateChange(newState) {
  // console.log(newState);
   if (newState == 1) {
    panel.setAttribute("style","right:-350px;");
    ads.setAttribute("style","left:-250px")
   }else if(newState == -1){
    panel.setAttribute("style","right:0");
   }else{
    ads.setAttribute("style","left:0");
    panel.setAttribute("style","right:0");
   };
}

// onStateChange
// -1 (unstarted)
// 0 (ended)
// 1 (playing)
// 2 (paused)
// 3 (buffering)
// 5 (video cued).